﻿using System;
using System.Collections.Generic;
using System.Linq;
using DeepZoomPivotConstructor.PivotLib;
using HtmlAgilityPack;
using PaperPluginUtilities;
using System.ComponentModel.Composition;

namespace ATLASConfNotes
{
    /// <summary>
    /// Scan a table for nodes in that table.
    /// </summary>
    [Export(typeof(ParseTableForImages))]
    public class ParseTableForImages
    {
        [Import]
        private ParseTableRowForImages rowParser = null;

        /// <summary>
        /// Looks at a single table to gather out the images.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public IEnumerable<PivotImage> Process(HtmlNode node)
        {
            if (node.Name != "table")
            {
                return Enumerable.Empty<PivotImage>();
            }

            rowParser.BaseUri = BaseUri;
            var images = node.ScanSubNodes("tr").SelectMany(subnode => rowParser.Process(subnode));
            return images;
        }

        public Uri BaseUri { get; set; }
    }
}
